package com.group.itms.routes.services;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import com.group.itms.routes.R;
import com.group.itms.routes.activities.UpdateDialogActivity;

class NotificationHelper {

	Context c;
	NotificationManager manager;

	NotificationHelper(Context c) {
		this.c = c;
		manager = (NotificationManager) c
				.getSystemService(Context.NOTIFICATION_SERVICE);
	}

	void notifySyncInProgress() {
		show(17, "Synchronization is in progress", emptyPendingIntent(17), true);
	}

	void cancelSyncNofitication() {
		manager.cancel(17);
	}
	
	void notifyUpdatesAvailable() {
		show(13, "New Content available", updateDialogIntent(13), false);
	}
	
	void cancelUpdatesNotification() {
		manager.cancel(13);
	}
	
	void show(int id, String title, PendingIntent pi, boolean ongoing) {
		Notification notif = getNotification(title, pi, ongoing);
		manager.notify(id, notif);
	}

	Notification getNotification(String title, PendingIntent pi, boolean ongoing) {
		return new NotificationCompat.Builder(c)
				.setContentTitle(title)
				.setSmallIcon(R.drawable.ic_launcher).setOngoing(ongoing)
				.setContentIntent(pi).build();
	}

	PendingIntent emptyPendingIntent(int id) {
		return PendingIntent.getActivity(c, id, new Intent(), 0);
	}

	PendingIntent updateDialogIntent(int id) {
		Intent i = new Intent(c, UpdateDialogActivity.class);
		return PendingIntent.getActivity(c, id, i, 0);
	}
	
}